package msu.ml.classification;

public class ThresholdSweepClassifier
{
   private double threshold;
   private int target;

   public ThresholdSweepClassifier(double threshold, int target)
   {
      this.threshold = threshold;
      this.target = target;
   }

   public int getSweepClassification(int [] counts)
   {
      int sum = 0;
      for(int i = 0; i < counts.length; i++)
         sum += counts[i];

      double [] dist = new double[counts.length];
      for(int i = 0; i < counts.length; i++)
         dist[i] = (double)counts[i] / (double)sum;

      if(dist[target] > threshold)
         return target;

      int highIndex = (target == 0) ? 1 : 0;
      for(int i = 0; i < dist.length; i++)
      {
         if(dist[i] > dist[highIndex] && i != target)
            highIndex = i;
      }
      return highIndex;

   }
}
